package com.iyue.user;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.iyue.SpringHelper;
import com.iyue.framework.BaseAction;
import com.iyue.servlet.taglibs.Functions;
import com.iyue.user.pojo.UserBasic;
import com.iyue.user.service.UserBiz;

/**
 * 《基本信息》实现类
 * 
 * @author luozm
 * @version $Id: Basic.java,v 1.7 2010/11/09 16:26:27 fresh Exp $
 */
public class Basic extends Profile {

	/**
	 * 修改头像
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @param action
	 * @return
	 * @throws Exception
	 */
	public ActionForward photoPost(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			BaseAction action) throws Exception {
		if (!isLogin(request)) {
			return action.display(request, response, "login");
		}

		String c = request.getParameter("c");
		if (c == null || c.isEmpty()) {
			c = "1";
			request.setAttribute("c", c);
		}

		Integer username = u(request);

		UserBiz biz = (UserBiz) SpringHelper.getBean("UserBiz");
		int ret = 0;
		UserBasic basic = new UserBasic();
		basic.setUsername(username);
		// basic.setMobile(user.getMobile());
		// basic.setPhoto(url);
		basic.setStatus(UserBasic.STATUS_OK);
		basic.setCreatetime(new Date());
		basic.setModifytime(new Date());

		biz.save_basic(basic);

		String forward = request.getParameter("go");
		if (ret <= 0) {
			request.setAttribute("msg", "修改失败!");
			if (forward != null && forward.length() > 3) {
				return new ActionForward(forward + "&msg="
						+ Functions.encode("修改失败!"), true);
			}
			back(request, "portal.do{0}&amp;do=Portal.my");

			return action.display(request, response, "info");
		}

		// int credit = CreditClient.credit(username, UserCredit.ACTION_PHOTO);
		// if (credit >= 0) {
		// MessageUtil.noticelog(username, SnsUtil.robotUser, 9, "{\"a\":[]}");
		// }

		String msg = "修改成功";
		if (forward != null && forward.length() > 3) {
			return new ActionForward(forward + "&msg=" + Functions.encode(msg),
					true);
		}

		back(request, "portal.do{0}&amp;do=Portal.my");

		return action.display(request, response, "info");
	}
}
